/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package GUI;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.SQLException;
import java.util.ArrayList;
import javax.swing.JOptionPane;import static persistencia.DBManagerPacientes.conexion;
import modelo.Pacientes;
import modelo.MetodosPacientes;


/**
 * En este panel eligiremos mediante un combobox el modelo a borrar
 * @author Kevin
 */
public class JPBorrarPaciente extends javax.swing.JPanel {
   
    ArrayList<Pacientes> al;
    
    
    
    public void actualizarComboBorrarPaciente() throws SQLException, ClassNotFoundException{
        jComboCodPaciente.removeAllItems();
        MetodosPacientes mtp= new MetodosPacientes();
        al = mtp.getIPacientes();
        for (int i = 0; i < al.size(); i++) {
            jComboCodPaciente.addItem(al.get(i).getCodPaciente()); //+al.get(i).getNombre());
        }
    }
   
        public JPBorrarPaciente() throws SQLException, ClassNotFoundException {
        initComponents();
        actualizarComboBorrarPaciente();

    
        jbBorrarPaciente.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                int codPaciente = (int)jComboCodPaciente.getSelectedItem();
                    Pacientes cPaciente = new Pacientes(Integer.toString(codPaciente));
                    
                
                MetodosPacientes mtp = null;
                try {
                    mtp = new MetodosPacientes();
                    mtp.delPaciente(cPaciente);
                    System.out.println ("EL PACIENTE HA SIDO BORRADO");
                    actualizarComboBorrarPaciente();
                } catch (ClassNotFoundException ex){
                    System.err.println ("DRIVER NO ENCONTRADO.");
                    ex.printStackTrace();
                } catch (SQLException ex) {
                    System.err.println ("SQLEXCEPTION.");
                    ex.printStackTrace();
                }
            }
        });
        
    }

    

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jlNombreMarca = new javax.swing.JLabel();
        jbBorrarPaciente = new javax.swing.JButton();
        jComboCodPaciente = new javax.swing.JComboBox();
        jLabelTitulo = new javax.swing.JLabel();

        jlNombreMarca.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jlNombreMarca.setText("Borrar Paciente:");

        jbBorrarPaciente.setText("Borrar");
        jbBorrarPaciente.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);

        jLabelTitulo.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
        jLabelTitulo.setText("Borrar Paciente");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jlNombreMarca)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 10, Short.MAX_VALUE)
                        .addComponent(jComboCodPaciente, javax.swing.GroupLayout.PREFERRED_SIZE, 274, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(152, 152, 152)
                                .addComponent(jbBorrarPaciente))
                            .addGroup(layout.createSequentialGroup()
                                .addGap(107, 107, 107)
                                .addComponent(jLabelTitulo)))
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabelTitulo)
                .addGap(78, 78, 78)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jComboCodPaciente, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jlNombreMarca, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 79, Short.MAX_VALUE)
                .addComponent(jbBorrarPaciente, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents


    // Variables declaration - do not modify//GEN-BEGIN:variables
    public javax.swing.JComboBox jComboCodPaciente;
    private javax.swing.JLabel jLabelTitulo;
    private javax.swing.JButton jbBorrarPaciente;
    private javax.swing.JLabel jlNombreMarca;
    // End of variables declaration//GEN-END:variables
}
